<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i> 属性修改</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-horizontal" role="form" method="post" action="" data-validate="validate">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">属性名称</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="属性名称" name="name" value="">
                                            </div>
                                            <!--<p class="col-sm-6 help-block">必填</p>-->
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">分类</label>
                                            <div class="col-sm-4">
                                                <select class="form-control" id="storage" name="storage">
                                                    <option value="-1">请选择</option>
                                                    <option value="0">冰鲜</option>
                                                    <option value="1">冻品</option>
                                                    <option value="2">远洋</option>
                                                    <option value="3">已加工</option>
                                                    <option value="4">养殖</option>
                                                </select>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">显示顺序</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="显示顺序" name="sort" value="0"><p>(越大显示越靠前)</p>
                                            </div>
                                        </div>
                                        <hr/>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">状态</label>
                                            <div class="col-sm-4">
                                                <select class="form-control" name="state" id="state">
                                                    <option value="0">不显示</option>
                                                    <option value="1" selected>显示</option>
                                                </select>
                                            </div>
                                        </div>
                                        <hr/>
                                        <div class="form-group">
                                            <div class=" col-sm-12">
                                                <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
                                            </div>
                                        </div>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>


<script>
    function validate($from) {
        return true;
    }

    $(document).ready(function () {
        $("form").attr("action", common_conf.requestUrl+'attribute/edit');
        getAttributeDetail($.getUrlVar('id'));
    });

    function getAttributeDetail(id) {
        $.ajax({
            type: 'post',
            url: common_conf.requestUrl+'attribute/detail',
            contentType : 'application/json;charset=UTF-8',
            cache: false,
            data: '{"id":'+id+'}',
            dataType: 'json',
            beforeSend: function () {
            },
            success: function (returnData) {
                if(forceLogin(returnData)) return;
                var obj=returnData;
                if(obj.state=="success"){
                    initFormData(obj.data);
                }else{
                    alert("获取失败");
                }
            },
            error: function () {
                alert("未找到模板");
            }
        });
    }

    function initFormData($attribute) {
        $("input[name='name']").val($attribute.name);
        $("input[name='sort']").val($attribute.sort);
        $("#storage").find("option").eq($attribute.storage+1).attr("selected",true);
        $("#state").find("option").eq($attribute.state).attr("selected",true);
        $('form').append("<input type='hidden' name='id' value='"+$attribute.id+"'>");
    }
</script>